/*
 * @description:
 * @version: 1.0.1
 * @Author: xuqiulin
 * @Date: 2021-05-01 10:44:53
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-05-01 15:18:42
 */
package conf

import (
	"github.com/BurntSushi/toml"
)

var Conf = &Config{}

type Config struct {
	Port      string   `toml:"Port"`
	GameHttp  string   `toml:"GameHttp"`
	Game      *MongoDB `toml:"Game"`
	GameLog   *MongoDB `toml:"GameLog"`
	GameAdmin *MongoDB `toml:"GameAdmin"`
}

type MongoDB struct {
	Addrs     string `toml:"Addrs"`
	PoolLimit int64  `toml:"PoolLimit"`
	Source    string `toml:"Source"` // 认证数据库
	Username  string `toml:"Username"`
	Password  string `toml:"Password"`
	Timeout   int64  `toml:"Timeout"`
	DbName    string `toml:"DbName"`
}

// Load loads config options from a toml file.
func (c *Config) Load(confFile string) error {
	_, err := toml.DecodeFile(confFile, c)
	if err != nil {
		return err
	}
	return nil
}

func (c *Config) LoadFromData(data string) error {
	_, err := toml.Decode(data, c)
	if err != nil {
		return err
	}
	return nil
}
